// pages/index/detail/detail.js

// const request = require("request")


Page({

      /**
       * 页面的初始数据
       */
      data: {
        category: null,
        pageIndex: 0,
        pageSize: 20,
        shops: [], //九宫格进来的对应的列表数据
        totalCount: 0,
        hasMore: true, //标记
      },
      loadMore() {
        let {
          pageIndex,
          pageSize,
          searchText
        } = this.data
        const params = {
          _page: ++pageIndex,
          _limit: pageSize
        }
        if (searchText) {
          params.q = searchText
        }
        return wx.request({
            url: `https://locally.uieee.com/categories/${this.data.category.id}/shops`,params,
            method: "get",
            success: (res) => {
              // console.log(res)
              const totalCount = parseInt(res.header['x-total-count'])
              const hasMore = this.data.pageIndex * this.data.pageSize < totalCount
              const shops = this.data.shops.concat(res.data)
              console.log(shops)
              this.setData({
                shops,
                totalCount,
                pageIndex,
                hasMore
              })

              wx.setNavigationBarTitle({
                title: res.data.name,
              })
            },
          },
        )},
          /**
           * 生命周期函数--监听页面加载
           */
          onLoad: function (options) {

            console.log(options)
            wx.request({
              url: `https://locally.uieee.com/categories/${options.cat}`,
              method: "get",
              success: (res) => {
                // console.log(res)
                this.setData({
                  category: res.data
                })

                wx.setNavigationBarTitle({
                  title: res.data.name,
                })
                this.loadMore();

              },


            })
          },

          /**
           * 生命周期函数--监听页面初次渲染完成
           */
          onReady: function () {

          },

          /**
           * 生命周期函数--监听页面显示
           */
          onShow: function () {

          },

          /**
           * 生命周期函数--监听页面隐藏
           */
          onHide: function () {

          },

          /**
           * 生命周期函数--监听页面卸载
           */
          onUnload: function () {

          },

          /**
           * 页面相关事件处理函数--监听用户下拉动作
           */
          onPullDownRefresh: function () {

          },

          /**
           * 页面上拉触底事件的处理函数
           */
          onReachBottom: function () {

          },

          /**
           * 用户点击右上角分享
           */
          onShareAppMessage: function () {

          }
        })